<?php

namespace Yolo\Log;

use function Hyperf\Support\env;

/**
 * Log
 * @author lushaoming<lushaoming6@gmail.com>
 * @date 2024/1/31
 */
class Log
{

    private static ?LogInterface $log = null;

    public static function getFactory(): LogInterface
    {
        if (!self::$log) {
            self::$log = self::getInstance();
        }

        return self::$log;
    }

    public static function debug(string|array $log): void
    {
        self::getFactory()->debug($log);
    }

    public static function info(string|array $log): void
    {
        self::getFactory()->info($log);
    }

    public static function warning(string|array $log): void
    {
        self::getFactory()->warning($log);
    }

    public static function error(string|array $log): void
    {
        self::getFactory()->error($log);
    }

    private static function getInstance(): LogInterface
    {
        $driver = env('LOG_DRIVER', 'file');

        return match ($driver) {
            'console' => new ConsoleLog(),
            default => new FileLog(),
        };
    }
}